<!DOCTYPE html>
<html lang='en'>
<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <title>Document</title>
</head>
    <style>
        .box {
            width: 800px;
            height: 600px;
            border: 1px solid black;
            margin: 0 auto;
            position: relative;
        }
        img {
            height: 100%;
        }
        .content {
            position: relative;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }
        a {
            display: block;
            width: 100%;
            height: 100%;
            top: 0px;
            left: 0px;
        }
        .left {
            position: absolute;
            top: 50%;
            margin-left: 10px;
        }
        .right {
            position: absolute;
            top: 50%;
            right: 0;
            margin-right: 10px;
        }
        .left,.right {
            font-size: 50px;
            font-weight: bolder;
        }
        .bottom-nav div {
            border-radius: 100px;
            background-color: #ccc;
            width: 20px;
            height: 20px;
        }
        .second {
            margin-left: 30px  ;
            margin-right: 30px;
        }
        .bottom-nav {
            display: flex;
            position: absolute;
            bottom: 0;
            margin-left: 355px;
        }
        button {
            background-color: transparent;
            border: 0;
        }
        .bottom-nav div:hover {
            cursor: pointer;
        }
        button:hover {
            box-shadow: 0px 0px 10px black;
        }
    </style>
<body>
    <div class="box">
        <div class="content">
            <a href="#"><img src="../statics/banner1.jpg" alt=""></a>
            <a href="#"><img src="../statics/banner2.jpg" alt=""></a>
            <a href="#"><img src="../statics/banner3.jpg" alt=""></a>
        </div>
        <button class="left" onclick="left()">&lt;</button> 
        <button class="right" onclick="right()">&gt;</button>
        <div class="bottom-nav">
            <div class="first"></div>
            <div class="second"></div>
            <div class="third"></div>
        </div>
    </div>
    <script>
        var index=0;
        var time;
        var imgList=document.querySelectorAll("a");
        var btnList=document.querySelectorAll(".bottom-nav div");
        public();
        autoPlay();
        btnClick();
        function public()
        {    
        for (var i = 0; i < imgList.length; i++) {
            imgList[i].style.display = "none";  // 隐藏所有图片
            btnList[i].style.backgroundColor="#ccc"
        }
        imgList[index].style.display = "block";  // 显示当前图片
        btnList[index].style.backgroundColor="blue"

        }
        function autoPlay()
        {
            time = setInterval(() => {
            index++;
            index%=imgList.length;
            console.log(index);
            public();            
        }, 3000);
        }

        function left()
        {
            clearInterval(time);
            index= index==0?imgList.length-1:index-1;
            public();
            autoPlay();  
        }
        function right()
        {
            clearInterval(time);
            index= index==imgList.length-1?0:index+1;
            public();
            autoPlay();  
        }
        function btnClick()
        {
            for(let i=0;i<btnList.length;i++)
            {
                btnList[i].onclick=function()
                {
                    clearInterval(time);
                    index=i;
                    console.log(i);                   
                    public();
                    autoPlay();
                }
            }
        }
    </script>
</body>
</html>